<?php

require_once(PATH_CLASS.'widget.class.php');
require_once(PATH_CLASS.'membre.class.php');

class player_admin extends widget{
  
  const CLASS_NAME = 'player_admin';

  public function getDefaults() {
    $ret = parent::getDefaults();
    $ret[self::C_SCRIPT_WRAP]=self::C_WRAP_BEGIN;
    $ret = array_merge(array(
       'id'         => null
      ,'pars'       => array()
      ,'more'       => array()
      ,'class'      => array('player')
    ),$ret);
    
    return $ret;
  }

  public function __construct($params) {
    parent::__construct($params);
    $this->addWidgetCss('team-player.css');
    $this->addJs('js/jquery.form.js');
  }
  
  protected function _get_called_class() { return self::CLASS_NAME;  }

  public function _render() {
    $pars = $this->params;
    
    if(isset ($pars['name']) && is_numeric($pars['name'])){
      $pars['id'] = $pars['name'];
    }
    
    if(isset($pars['id'])){
      $membre = membre::getMembreById($pars['id']);
    } else if (isset ($pars['name'])){
      $membre = membre::getMembreByName($pars['name']);
    }
    
    if($membre!=null){
      $params = array(
          'membre'      =>  $membre
          ,'membre_id'  =>  $membre->membre_id
      );

      $params = array_merge($params,$pars);
      
      $layout = $this->renderTplFromFile(__FILE__, $params);
      
    } else {
      $layout='';
    }
    
    return $layout;
  }
}

